<?php

namespace Admin\Controller;


use Admin\Common\Page;

class LogRefundController extends BaseController{

    public function index(){

        $keyword = I('get.keyword');
        if (!empty($keyword)) {
            $where['a.refund_id'] = $keyword;
            $where['b.card_id'] = $keyword;
            $where['_logic'] = 'or';
            $map['_complex'] = $where;
        }

        $interval_time = I('get.interval_time');
        if (!empty($interval_time)) {
            $time=explode('~',$interval_time);
            $time[0]=$time[0].' 00:00:00';
            $time[1]=$time[1].' 23:59:59';
            $map['a.create_time'] = [
                ['gt',$time[0]],
                ['lt',$time[1]]
            ];
        }

        $type = I("get.type");
        if(!empty($type)){
            $map['a.type'] = $type;
        }

        $count = M('refund')->alias('a')->join('card b on a.user_id=b.user_id','left')->where($map)->count();// 查询满足要求的总记录数
        $Page = new  \Admin\Common\Page($count , C('page.size'));// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show = $Page->show();// 分页显示输出
        $this->assign('page' , $show);// 赋值分页输出
        $data = M('refund')->alias('a')
            ->where($map)
            ->join('card b on a.user_id=b.user_id','left')
            ->field('a.*,b.card_id')
            ->order('a.create_time desc')
            ->limit($Page->firstRow . ',' . $Page->listRows)
            ->select();




        if(I("get.execl")==1){
            $file = excel_export($data);
            ouput_Browser($file);
        }else{
            $this->data = $data;
            $this->display();
        }

    }

}